﻿using System;
using NUnit.Framework;
using TechTalk.SpecFlow;

namespace Matrix.Data.Tests
{
   [Binding]
   public class MatrixData_TC02_Steps
   {
      private Func<Matrix> _mathOperation;

      [Given(@"that '(.*)' equals Matrix:")]
      public void GivenThatEqualsMatrix(string key, string stringMatrix)
      {
         ScenarioContext.Current[key] = Matrix.Parse(stringMatrix);
      }

      [When(@"I '(.*)' the matrices '(.*)'")]
      public void WhenITheMatrices(string operatorSymbol, string operands)
      {
         var ops = operands.Split(',');

         var op1 = ScenarioContext.Current[ops[0]] as Matrix;
         var op2 = ScenarioContext.Current[ops[1]] as Matrix;

         switch (operatorSymbol)
         {
            case "add":
               _mathOperation = () => op1 + op2;
               break;
            case "subtract":
               _mathOperation = () => op1 - op2;
               break;
            case "multiply":
               _mathOperation = () => op1 * op2;
               break;
         }
      }

      [Then(@"the resulting Matrix should be '(.*)'")]
      public void ThenTheResultingMatrixShouldBe(string resultMatrix)
      {
         var result = ScenarioContext.Current[resultMatrix] as Matrix;
         Assert.That(_mathOperation.Invoke().mat.Equals(result.mat));
      }
   }
}
